package com.yhao.stock.controller;


import com.yhao.stock.common.service.THSService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * <p>
 * 股票信息表 前端控制器
 * </p>
 *
 * @author yhao
 * @since 2023-11-09
 */
@RestController
@RequestMapping("/stockInfo")
@Slf4j
public class StockInfoController {

    @Autowired
    private THSService thsService;

    @GetMapping("/toQuery")
    public void toQuery(Model model, HttpServletRequest request, HttpServletResponse response) {
        String dCode = request.getParameter("dCode");
        String dName = request.getParameter("dName");

        System.out.println(dCode + "   " + dName);

        String result = "{\n" +
                "        xAxis: {\n" +
                "            type: 'category',\n" +
                "            data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']\n" +
                "        },\n" +
                "        yAxis: {\n" +
                "            type: 'value'\n" +
                "        },\n" +
                "        series: [\n" +
                "            {\n" +
                "                data: [150, 230, 224, 218, 135, 147, 260],\n" +
                "                type: 'line'\n" +
                "            },\n" +
                "            {\n" +
                "                data: [350, 130, 424, 618, 235, 47, 160],\n" +
                "                type: 'line'\n" +
                "            }\n" +
                "        ]\n" +
                "    }";

        try {
            response.getWriter().write(result);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    @GetMapping("/getAll")
    public String getAllStockInfo() {
        // 获取上证的数据
        String azBaseUrl = "https://q.10jqka.com.cn/index/index/board/hs/field/zdf/order/desc/page/";
        thsService.getAllStockBaseInfo(111, azBaseUrl);


        // 获取上证的数据             /index/index/board/ss/field/zdf/order/desc/page/1/ajax/1/
        String szBaseUrl = "https://q.10jqka.com.cn/index/index/board/ss/field/zdf/order/desc/page/";
        thsService.getAllStockBaseInfo(142, szBaseUrl);


        // 获取上证的数据
        String cyBaseUrl = "https://q.10jqka.com.cn/index/index/board/cyb/field/zdf/order/desc/page/";
        thsService.getAllStockBaseInfo(67, cyBaseUrl);

        return "success";
    }


}
